package com.example.demo.consumer;

import com.innodealing.offsetskip.annotation.KafkaOffsetSkip;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class KafkaAutoCommitConsumer {

    @KafkaListener(
        topics = "demo-skip-auto", 
        groupId = "demo-skip-auto-group",
        containerFactory = "autoCommitKafkaListenerContainerFactory"
    )
    @KafkaOffsetSkip
    public void consume(ConsumerRecord<String, String> record) {
        System.out.println("=== 自动提交消费者方法被调用 ===");
        String value = record.value();
        
        // 模拟业务处理逻辑
        if (value.contains("error")) {
            throw new RuntimeException("业务处理异常: " + value);
        }
        
        System.out.println("自动提交模式 - 处理成功: " + value);
        // 自动提交模式下不需要手动确认，Spring Kafka会自动处理
    }
}
